﻿package frEngine.animateControler.particleControler
{
    import __AS3__.vec.*;
    import baseEngine.core.*;
    import baseEngine.system.*;
    import baseEngine.utils.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.*;
    import frEngine.animateControler.*;
    import frEngine.animateControler.keyframe.*;
    import frEngine.core.mesh.*;
    import frEngine.event.*;
    import frEngine.loaders.*;
    import frEngine.render.layer.*;
    import frEngine.shader.*;
    import frEngine.shader.registType.*;

    public class ParticleAnimateControler extends MeshAnimateBase implements IRender
    {
        protected var _particleParams:ParticleParams;
        protected var _globlePoint:Vector3D;
        private var _oldGloblePoint:Vector3D;
        private var _oldControlPoint:Vector3D;
        private var _tempVect3d:Vector3D;
        private var _tempVect3d2:Vector3D;
        private var timeOffset:VcParam;
        private var _distanceBirthNum:int;
        private var _maxDuring:int = 0;
        private var _perMaxDuring:int = 0;
        private var _playMode:int = 0;
        private var hasUpload:Boolean;
        private var _transformMatrix3d:Matrix3D;
        private var _faceCameraRegister:MaxtrixParam;
        private var vc0_60:Vector.<Number>;
        private var globlePositionRegist:VcParam;
        private var endPositionRegist:VcParam;
        private var globleRotaionValue:Matrix3D;
        private var globalScaleValue:Vector.<Number>;
        protected var _emitterTime:int = 0;
        protected var _curStarPlayTime:int = 0;
        private var preDuring:int = -1;
        private var _oldIndex:Number = 0;
        private var _toltalParticleNum:int = 0;
        private var _numOfMeshVertex:int = 1;
        private var _perParticleEmitterTime:Number;
        private var _emmitFinish:Boolean;
        private var _birthDistance:int;
        private var curIndex:int = 0;
        private var tailMaxDistance:int;
        private var tailPerDistance:Number;
        private var _needUpdataTail:Boolean;
        private var _needUpDistanceBirth:Boolean;
        public var useEndPoint:Boolean = false;
        protected var _useTargetEndPoint:Boolean = false;
        private var _targetMultyplaySpeed:int = 0;
        private var _targetStartPos:Vector3D;
        private var _targetEndPos:Vector3D;
        private var _preFrame:int = -1;
        private var _preTime:int = 0;
        private var _particleCircles:Vector.<int>;
        public var lineRoadControler:LineRoadControler;
        public var emmitFlag:uint = 1;
        private var _useRotation:Boolean = false;
        private var _useScale:Boolean = true;
        public var needUpdateTransform:Boolean = true;
        private var selfIndividualBuffer:Vector.<Number>;
        private static var _zeroPoint:Vector3D = new Vector3D(0, 0, 0, 1);
        private static var _right:Vector3D = new Vector3D();
        private static var _up:Vector3D = new Vector3D();
        private static var _dir:Vector3D = new Vector3D();

        public function ParticleAnimateControler()
        {
            this._globlePoint = new Vector3D();
            this._oldGloblePoint = new Vector3D();
            this._oldControlPoint = new Vector3D();
            this._tempVect3d = new Vector3D();
            this._tempVect3d2 = new Vector3D();
            this.vc0_60 = new Vector.<Number>;
            this.globleRotaionValue = new Matrix3D();
            this.globalScaleValue = this.Vector.<Number>([1, 1, 1, 1]);
            return;
        }// end function

        public function set useTargetEndPoint(param1:Boolean) : void
        {
            this._useTargetEndPoint = param1;
            return;
        }// end function

        public function set useScale(param1:Boolean) : void
        {
            this._useScale = param1;
            if (param1)
            {
                this.updateTransformHander(null);
            }
            else
            {
                var _loc_2:int = 1;
                this.globalScaleValue[2] = 1;
                var _loc_2:* = _loc_2;
                this.globalScaleValue[1] = _loc_2;
                this.globalScaleValue[0] = _loc_2;
            }
            return;
        }// end function

        public function set useRotation(param1:Boolean) : void
        {
            this._useRotation = param1;
            if (param1)
            {
                this.updateTransformHander(null);
            }
            else
            {
                this.globleRotaionValue.identity();
            }
            return;
        }// end function

        override protected function setSurfaceHander(event:Event) : void
        {
            super.setSurfaceHander(event);
            FrEventDispatcher.instance.proxyAddEventListener(targetMesh.material, Engine3dEventName.MATERIAL_REBUILDER, this.setingParams);
            return;
        }// end function

        override public function set targetObject3d(param1:Pivot3D) : void
        {
            if (targetObject3d)
            {
                FrEventDispatcher.instance.proxyRemoveEventListener(targetObject3d, Engine3dEventName.UPDATE_TRANSFORM_EVENT, this.updateTransformHander);
                FrEventDispatcher.instance.proxyRemoveEventListener(targetObject3d, Engine3dEventName.PARENT_CHANGE_EVENT, this.updateTransformHander);
                FrEventDispatcher.instance.proxyRemoveEventListener(targetObject3d, Engine3dEventName.VISIBLE_CHANGE_EVENT, this.visibleChangeHander);
            }
            super.targetObject3d = param1;
            if (param1)
            {
                FrEventDispatcher.instance.proxyAddEventListener(param1, Engine3dEventName.VISIBLE_CHANGE_EVENT, this.visibleChangeHander);
                FrEventDispatcher.instance.proxyAddEventListener(param1, Engine3dEventName.PARENT_CHANGE_EVENT, this.updateTransformHander);
                FrEventDispatcher.instance.proxyAddEventListener(param1, Engine3dEventName.UPDATE_TRANSFORM_EVENT, this.updateTransformHander);
                this.updateTransformHander(null);
            }
            return;
        }// end function

        private function updateTransformHander(event:Event) : void
        {
            if (!targetMesh)
            {
                return;
            }
            this.needUpdateTransform = true;
            return;
        }// end function

        private function toUpdateParticleTransform() : void
        {
            var _loc_1:Matrix3D = null;
            var _loc_2:Pivot3D = null;
            this.needUpdateTransform = false;
            if (this._useRotation)
            {
                _loc_1 = targetMesh.world;
                _loc_1.copyColumnTo(0, _right);
                _loc_1.copyColumnTo(1, _up);
                _loc_1.copyColumnTo(2, _dir);
                _right.normalize();
                _up.normalize();
                _dir.normalize();
                var _loc_3:int = 0;
                _right.w = 0;
                var _loc_3:* = _loc_3;
                _up.w = _loc_3;
                _dir.w = _loc_3;
                this.globleRotaionValue.copyColumnFrom(0, _right);
                this.globleRotaionValue.copyColumnFrom(1, _up);
                this.globleRotaionValue.copyColumnFrom(2, _dir);
            }
            if (this._useScale)
            {
                _loc_2 = targetMesh.parent;
                if (_loc_2)
                {
                    Matrix3DUtils.getScale(targetMesh.world, this._tempVect3d);
                    this.globalScaleValue[0] = this._tempVect3d.x;
                    this.globalScaleValue[1] = this._tempVect3d.y;
                    this.globalScaleValue[2] = this._tempVect3d.z;
                }
                else
                {
                    this.globalScaleValue[0] = targetMesh.scaleX;
                    this.globalScaleValue[1] = targetMesh.scaleY;
                    this.globalScaleValue[2] = targetMesh.scaleZ;
                }
            }
            return;
        }// end function

        public function set particleParams(param1:ParticleParams) : void
        {
            var _loc_2:Label3D = null;
            this._particleParams = param1;
            if (!this._particleParams || !param1.hasCompleted)
            {
                this._emmitFinish = false;
                return;
            }
            this._distanceBirthNum = this._particleParams.distanceBirthNum;
            this._emitterTime = this._particleParams.emitterTime;
            this._playMode = this._particleParams.playMode;
            this._birthDistance = this._particleParams.birthDistance;
            this.vc0_60.length = 0;
            this.curIndex = 0;
            if (this._particleParams.emitCountType == EngineConstName.emmitUser)
            {
                this._toltalParticleNum = this._particleParams.emitUserObject.emitMaxTime;
            }
            else
            {
                this._toltalParticleNum = this._particleParams.total_number;
            }
            this._numOfMeshVertex = this._particleParams.numOfmeshVertex;
            this.tailMaxDistance = this._particleParams.tailMaxDistance;
            this.tailPerDistance = this.tailMaxDistance / this._toltalParticleNum;
            this._perParticleEmitterTime = this._particleParams.perParticleEmitterTime;
            this._maxDuring = this._particleParams.maxDuring;
            this._needUpdataTail = this._particleParams.tailEnabled;
            this._needUpDistanceBirth = this._particleParams.distanceBirth;
            this.useEndPoint = this._particleParams.useEndPoint;
            this._perMaxDuring = this._needUpDistanceBirth ? (1) : (this._maxDuring);
            if (this.timeOffset)
            {
                this.timeOffset.changeValue1(2, this._perMaxDuring);
            }
            if (!cuPlayLable)
            {
                _loc_2 = new Label3D(0, int((this._particleParams.totalTime - 1)), "default", 0);
                this.setPlayLable(_loc_2);
            }
            else
            {
                this.cuPlayLable.change(0, (this._particleParams.totalTime - 1));
            }
            this.toUpdateAnimate(true);
            return;
        }// end function

        override public function get type() : int
        {
            return AnimateControlerType.ParticleAnimateControler;
        }// end function

        private function visibleChangeHander(event:Event) : void
        {
            this._curStarPlayTime = targetObject3d.timerContorler.curFrame;
            if (targetObject3d.visible)
            {
                this.reset();
            }
            return;
        }// end function

        public function reset() : void
        {
            if (this._needUpDistanceBirth || this._needUpdataTail)
            {
                this.vc0_60.length = 0;
                this.curIndex = 0;
            }
            this._lastFrame = this.currentFrame - 1;
            return;
        }// end function

        protected function setingParams(event:Event) : void
        {
            var _loc_4:Vector3D = null;
            var _loc_5:VcParam = null;
            var _loc_6:XYZObject = null;
            var _loc_7:VcParam = null;
            var _loc_8:XYZObject = null;
            var _loc_9:XYZObject = null;
            var _loc_10:VcParam = null;
            var _loc_11:XYZObject = null;
            this.timeOffset = targetMesh.material.getParam("{time_perCircleTime_maxDuring_nearOne}", true);
            this.timeOffset.changeValue3(0, this._particleParams.emitterLife, this._perMaxDuring);
            if (this._particleParams.distanceBirth || this._particleParams.tailEnabled)
            {
                targetMesh.material.getParam("{vc0-60}", true).value = this.vc0_60;
            }
            else
            {
                this.globlePositionRegist = targetMesh.material.getParam("{globlePosition}", true);
            }
            if (this._particleParams.useEndPoint)
            {
                this.endPositionRegist = targetMesh.material.getParam("{endPoint}", true);
                if (this._useTargetEndPoint)
                {
                    _loc_4 = ParticleMesh(targetMesh).hangObjPoint;
                    this.endPositionRegist.changeValue3(_loc_4.x, _loc_4.y, _loc_4.z);
                }
                else
                {
                    this.endPositionRegist.changeValue3(this._particleParams.destinationX, this._particleParams.destinationY, this._particleParams.destinationZ);
                }
            }
            var _loc_2:* = targetMesh.material.getParam("{globleRotation}", true);
            _loc_2.value = this.globleRotaionValue;
            var _loc_3:* = targetMesh.material.getParam("{localScale}", true);
            _loc_3.value = this.globalScaleValue;
            if (this._particleParams.faceCamera)
            {
                this._faceCameraRegister = targetMesh.material.getParam("{rotationMatrixRegister}", true);
            }
            if (this._particleParams.useLineForce)
            {
                _loc_5 = targetMesh.material.getParam("{lineForce}", true);
                _loc_6 = this._particleParams.lineForceVecor3d;
                _loc_5.changeValue4(_loc_6.x, _loc_6.y, _loc_6.z, _loc_6.w);
            }
            if (this._particleParams.useSimpleHarmonicVibration)
            {
                _loc_7 = targetMesh.material.getParam("{shvDirection}", true);
                _loc_8 = this._particleParams.shvDirection;
                _loc_7.changeValue3(_loc_8.x, _loc_8.y, _loc_8.z);
                _loc_7 = targetMesh.material.getParam("{shvValue}", true);
                _loc_9 = this._particleParams.shvValue;
                _loc_7.changeValue4(_loc_9.x, _loc_9.y, _loc_9.z, _loc_9.w);
            }
            if (this._particleParams.useFriction && this._particleParams.useSpeed)
            {
                _loc_10 = targetMesh.material.getParam("{frictionSize}", true);
                _loc_11 = this._particleParams.frictionVecor3d;
                _loc_10.changeValue3(1000 / _loc_11.x, 1000 / _loc_11.y, 1000 / _loc_11.z);
            }
            this.needUpdateTransform = true;
            this.hasUpload = true;
            this.toUpdateAnimate(true);
            return;
        }// end function

        override public function play() : void
        {
            if (_isPlaying)
            {
                return;
            }
            super.play();
            return;
        }// end function

        private function updataTailPath(param1:Number) : void
        {
            var _loc_14:int = 0;
            var _loc_15:int = 0;
            var _loc_16:int = 0;
            var _loc_17:int = 0;
            var _loc_18:int = 0;
            var _loc_19:int = 0;
            var _loc_20:Vector.<Vector3D> = null;
            var _loc_21:Vector3D = null;
            var _loc_22:Number = NaN;
            var _loc_23:Number = NaN;
            var _loc_24:Number = NaN;
            var _loc_25:Number = NaN;
            var _loc_26:Number = NaN;
            var _loc_27:Number = NaN;
            var _loc_28:Number = NaN;
            var _loc_29:Number = NaN;
            var _loc_30:Number = NaN;
            if ((this._preFrame == this.currentFrame || param1 > this._emitterTime) && this.vc0_60.length > 0)
            {
                return;
            }
            var _loc_2:* = this.emmitFlag;
            if (this.currentFrame < this._preFrame)
            {
                this.vc0_60.length = 0;
            }
            this._preFrame = this.currentFrame;
            var _loc_3:* = this._globlePoint.x;
            var _loc_4:* = this._globlePoint.y;
            var _loc_5:* = this._globlePoint.z;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            if (this.vc0_60.length == 0)
            {
                this.vc0_60.length = this._toltalParticleNum * 4;
                _loc_6 = 0;
                while (_loc_6 < this._toltalParticleNum)
                {
                    
                    _loc_7 = _loc_6 * 4;
                    this.vc0_60[_loc_7] = _loc_3;
                    this.vc0_60[(_loc_7 + 1)] = _loc_4;
                    this.vc0_60[_loc_7 + 2] = _loc_5;
                    this.vc0_60[_loc_7 + 3] = _loc_2;
                    _loc_6++;
                }
                this._oldGloblePoint = this._globlePoint.clone();
                this._oldControlPoint = this._oldGloblePoint.clone();
            }
            this.curIndex = int(param1 / this._perParticleEmitterTime);
            if (this.curIndex > this._toltalParticleNum)
            {
                return;
            }
            var _loc_8:* = this._oldGloblePoint.x;
            var _loc_9:* = this._oldGloblePoint.y;
            var _loc_10:* = this._oldGloblePoint.z;
            this._tempVect3d2.x = _loc_3 - _loc_8;
            this._tempVect3d2.y = _loc_4 - _loc_9;
            this._tempVect3d2.z = _loc_5 - _loc_10;
            var _loc_11:* = this._tempVect3d2.normalize();
            if (_loc_11 > 250)
            {
                _loc_2 = 0;
            }
            var _loc_12:* = (this.curIndex - this._oldIndex + this._toltalParticleNum) % this._toltalParticleNum;
            var _loc_13:* = int(_loc_11 / this.tailPerDistance);
            if (_loc_13 > 1)
            {
                if (_loc_13 > this._toltalParticleNum)
                {
                    _loc_13 = this._toltalParticleNum;
                }
                _loc_13 = Math.max(_loc_13, _loc_12);
                _loc_15 = _loc_13 - _loc_12;
                if (_loc_15 > 0)
                {
                    _loc_16 = this._toltalParticleNum - _loc_13;
                    _loc_6 = 1;
                    while (_loc_6 <= _loc_16)
                    {
                        
                        _loc_17 = this.curIndex + _loc_6;
                        var _loc_31:* = _loc_17 - this._toltalParticleNum;
                        _loc_17 = _loc_17 - this._toltalParticleNum;
                        _loc_18 = _loc_17 + _loc_15;
                        var _loc_31:* = _loc_18 - this._toltalParticleNum;
                        _loc_18 = _loc_18 - this._toltalParticleNum;
                        _loc_7 = _loc_17 * 4;
                        _loc_19 = _loc_18 * 4;
                        this.vc0_60[_loc_7] = this.vc0_60[_loc_19];
                        this.vc0_60[(_loc_7 + 1)] = this.vc0_60[(_loc_19 + 1)];
                        this.vc0_60[_loc_7 + 2] = this.vc0_60[_loc_19 + 2];
                        this.vc0_60[_loc_7 + 3] = this.vc0_60[_loc_19 + 3];
                        _loc_6++;
                    }
                }
                if (this.lineRoadControler)
                {
                    _loc_20 = this.lineRoadControler.getMidPos(_loc_13);
                    _loc_14 = this.curIndex - _loc_13;
                    var _loc_31:* = _loc_14 + this._toltalParticleNum;
                    _loc_14 = _loc_14 + this._toltalParticleNum;
                    _loc_6 = 0;
                    while (_loc_6 < _loc_13)
                    {
                        
                        _loc_21 = _loc_20[_loc_6];
                        _loc_14++;
                        var _loc_31:* = _loc_14 - this._toltalParticleNum;
                        _loc_14 = _loc_14 - this._toltalParticleNum;
                        _loc_7 = _loc_14 * 4;
                        this.vc0_60[_loc_7] = _loc_21.x;
                        this.vc0_60[(_loc_7 + 1)] = _loc_21.y;
                        this.vc0_60[_loc_7 + 2] = _loc_21.z;
                        this.vc0_60[_loc_7 + 3] = _loc_2;
                        _loc_6++;
                    }
                }
                else
                {
                    this._tempVect3d.x = _loc_8 - this._oldControlPoint.x;
                    this._tempVect3d.y = _loc_9 - this._oldControlPoint.y;
                    this._tempVect3d.z = _loc_10 - this._oldControlPoint.z;
                    this._tempVect3d.normalize();
                    this._tempVect3d.scaleBy(_loc_11 * 0.5);
                    _loc_22 = this._tempVect3d.x + _loc_8;
                    _loc_23 = this._tempVect3d.y + _loc_9;
                    _loc_24 = this._tempVect3d.z + _loc_10;
                    _loc_25 = _loc_11 == 0 ? (0) : (this.tailMaxDistance / _loc_11);
                    if (_loc_25 > 1)
                    {
                        _loc_25 = 1;
                    }
                    _loc_6 = 0;
                    while (_loc_6 < _loc_13)
                    {
                        
                        _loc_26 = _loc_6 / _loc_13 * _loc_25;
                        _loc_27 = _loc_26 * _loc_26;
                        _loc_28 = 1 - _loc_26;
                        _loc_29 = _loc_28 * _loc_28;
                        _loc_30 = 2 * _loc_26 * _loc_28;
                        _loc_14 = this.curIndex - _loc_6;
                        var _loc_31:* = _loc_14 + this._toltalParticleNum;
                        _loc_14 = _loc_14 + this._toltalParticleNum;
                        _loc_7 = _loc_14 * 4;
                        this.vc0_60[_loc_7] = _loc_3 * _loc_29 + _loc_22 * _loc_30 + _loc_8 * _loc_27;
                        this.vc0_60[(_loc_7 + 1)] = _loc_4 * _loc_29 + _loc_23 * _loc_30 + _loc_9 * _loc_27;
                        this.vc0_60[_loc_7 + 2] = _loc_5 * _loc_29 + _loc_24 * _loc_30 + _loc_10 * _loc_27;
                        this.vc0_60[_loc_7 + 3] = _loc_2;
                        _loc_6++;
                    }
                    this._oldControlPoint.setTo(_loc_22, _loc_23, _loc_24);
                }
                this._oldGloblePoint.setTo(_loc_3, _loc_4, _loc_5);
                this._oldIndex = this.curIndex;
            }
            else
            {
                _loc_6 = 0;
                while (_loc_6 < _loc_12)
                {
                    
                    _loc_14 = this.curIndex - _loc_6;
                    var _loc_31:* = _loc_14 + this._toltalParticleNum;
                    _loc_14 = _loc_14 + this._toltalParticleNum;
                    _loc_7 = _loc_14 * 4;
                    this.vc0_60[_loc_7] = _loc_3;
                    this.vc0_60[(_loc_7 + 1)] = _loc_4;
                    this.vc0_60[_loc_7 + 2] = _loc_5;
                    this.vc0_60[_loc_7 + 3] = _loc_2;
                    _loc_6++;
                }
                this._oldGloblePoint.setTo(_loc_3, _loc_4, _loc_5);
                this._oldIndex = this.curIndex;
            }
            return;
        }// end function

        private function updataDistanceBirth(param1:int) : void
        {
            var _loc_11:Number = NaN;
            var _loc_12:Number = NaN;
            var _loc_13:Number = NaN;
            var _loc_14:int = 0;
            var _loc_15:Number = NaN;
            var _loc_16:Number = NaN;
            var _loc_17:Number = NaN;
            var _loc_18:Number = NaN;
            var _loc_19:Number = NaN;
            var _loc_20:Number = NaN;
            if (this._preFrame == this.currentFrame || param1 > this._emitterTime)
            {
                return;
            }
            if (this.currentFrame < this._preFrame)
            {
                this.vc0_60.length = 0;
                this.curIndex = 0;
            }
            this._preFrame = this.currentFrame;
            var _loc_2:* = this._globlePoint.x;
            var _loc_3:* = this._globlePoint.y;
            var _loc_4:* = this._globlePoint.z;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            if (this.vc0_60.length == 0)
            {
                this.vc0_60.length = this._distanceBirthNum * 4;
                _loc_5 = 0;
                while (_loc_5 < this._distanceBirthNum)
                {
                    
                    _loc_6 = _loc_5 * 4;
                    this.vc0_60[_loc_6] = _loc_2;
                    this.vc0_60[(_loc_6 + 1)] = _loc_3;
                    this.vc0_60[_loc_6 + 2] = _loc_4;
                    this.vc0_60[_loc_6 + 3] = -10000;
                    _loc_5++;
                }
                this._oldGloblePoint = this._globlePoint.clone();
                this._oldControlPoint = this._oldGloblePoint.clone();
                this._preTime = param1;
            }
            var _loc_7:* = this._oldGloblePoint.x;
            var _loc_8:* = this._oldGloblePoint.y;
            var _loc_9:* = this._oldGloblePoint.z;
            this._tempVect3d2.x = _loc_2 - _loc_7;
            this._tempVect3d2.y = _loc_3 - _loc_8;
            this._tempVect3d2.z = _loc_4 - _loc_9;
            var _loc_10:* = this._tempVect3d2.normalize();
            if (_loc_10 >= this._birthDistance)
            {
                this._tempVect3d.x = _loc_7 - this._oldControlPoint.x;
                this._tempVect3d.y = _loc_8 - this._oldControlPoint.y;
                this._tempVect3d.z = _loc_9 - this._oldControlPoint.z;
                this._tempVect3d.normalize();
                this._tempVect3d.scaleBy(_loc_10 / 2);
                _loc_11 = this._tempVect3d.x + _loc_7;
                _loc_12 = this._tempVect3d.y + _loc_8;
                _loc_13 = this._tempVect3d.z + _loc_9;
                _loc_14 = Math.floor(_loc_10 / this._birthDistance);
                _loc_15 = (param1 - this._preTime) / _loc_14;
                _loc_5 = 1;
                while (_loc_5 <= _loc_14)
                {
                    
                    _loc_16 = 1 - _loc_5 / _loc_14;
                    _loc_17 = _loc_16 * _loc_16;
                    _loc_18 = 1 - _loc_16;
                    _loc_19 = _loc_18 * _loc_18;
                    _loc_20 = 2 * _loc_16 * _loc_18;
                    this.curIndex = (this.curIndex + 1) % this._distanceBirthNum;
                    _loc_6 = this.curIndex * 4;
                    this.vc0_60[_loc_6] = _loc_2 * _loc_19 + _loc_11 * _loc_20 + _loc_7 * _loc_17;
                    this.vc0_60[(_loc_6 + 1)] = _loc_3 * _loc_19 + _loc_12 * _loc_20 + _loc_8 * _loc_17;
                    this.vc0_60[_loc_6 + 2] = _loc_4 * _loc_19 + _loc_13 * _loc_20 + _loc_9 * _loc_17;
                    this.vc0_60[_loc_6 + 3] = this._preTime + _loc_5 * _loc_15;
                    _loc_5++;
                }
                this._oldControlPoint.setTo(_loc_11, _loc_12, _loc_13);
                this._oldGloblePoint.setTo(_loc_2, _loc_3, _loc_4);
                this._preTime = param1;
            }
            return;
        }// end function

        override protected function updateCurFrame() : void
        {
            var _loc_1:Number = NaN;
            var _loc_3:Boolean = false;
            if (this._playMode == 1)
            {
                _loc_1 = targetMesh.timerContorler.totalframe;
            }
            else
            {
                _loc_1 = targetMesh.timerContorler.curFrame;
            }
            var _loc_2:* = cuPlayLable.length;
            if (_loc_1 >= _loc_2)
            {
                _loc_1 = _loc_2 - 1;
            }
            else if (_loc_1 < 0)
            {
                _loc_1 = 0;
            }
            this.currentFrame = cuPlayLable.from + _loc_1;
            return;
        }// end function

        override public function toUpdateAnimate(param1:Boolean = false) : void
        {
            var _loc_4:Vector3D = null;
            if (!this._particleParams)
            {
                return;
            }
            super.toUpdateAnimate(param1);
            targetObject3d.world.copyColumnTo(3, this._globlePoint);
            if (!param1 && !changeFrame || !this.hasUpload)
            {
                return;
            }
            var _loc_2:* = this._currentFrame - this._curStarPlayTime;
            if (_loc_2 < 0)
            {
                _loc_2 = 0;
            }
            var _loc_3:* = int(_loc_2 / this._particleParams.emitterLife);
            this._emmitFinish = _loc_3 > this._maxDuring ? (true) : (false);
            if (this._emmitFinish)
            {
                return;
            }
            this.timeOffset.changeValue1(0, _loc_2);
            if (this.useEndPoint && this._useTargetEndPoint && this.endPositionRegist)
            {
                _loc_4 = ParticleMesh(targetMesh).hangObjPoint;
                this.endPositionRegist.changeValue3(_loc_4.x, _loc_4.y, _loc_4.z);
            }
            else if (this._needUpDistanceBirth)
            {
                this.updataDistanceBirth(_loc_2 - _loc_3 * this._particleParams.emitterLife);
            }
            else if (this._needUpdataTail)
            {
                this.updataTailPath(_loc_2 - _loc_3 * this._particleParams.emitterLife);
            }
            if (this._faceCameraRegister)
            {
                this._faceCameraRegister.value = Device3D.faceCameraMatrix3d;
            }
            return;
        }// end function

        public function completeDraw(param1:Mesh3D) : void
        {
            return;
        }// end function

        public function drawEdge(param1:Mesh3D, param2:Number = 1, param3:Number = 1, param4:Number = 1) : void
        {
            return;
        }// end function

        public function drawDepth(param1:Mesh3D, param2:Number = 1, param3:Number = 1, param4:Number = 1, param5:Number = 1) : void
        {
            return;
        }// end function

        public function draw(param1:Mesh3D, param2:ShaderBase = null) : void
        {
            if (!targetMesh.material || !this._particleParams || this._emmitFinish)
            {
                return;
            }
            if (!targetSurface || !targetMesh.material.hasPrepared(param1, targetSurface))
            {
                return;
            }
            if (this.needUpdateTransform)
            {
                targetObject3d.world.copyColumnTo(3, this._globlePoint);
                this.toUpdateParticleTransform();
            }
            var _loc_4:* = Global3D;
            var _loc_5:* = Global3D.objectsDrawn + 1;
            _loc_4.objectsDrawn = _loc_5;
            var _loc_3:* = param1.material.materialParams;
            if (_loc_3.enableMask && param1.layer != Layer3DManager.warpLayer)
            {
                Global3D.scene.context.setStencilReferenceValue(0);
            }
            targetMesh.material.draw(param1, targetSurface, _loc_3.depthCompare, _loc_3.cullFace, _loc_3.depthWrite, _loc_3.sourceFactor, _loc_3.destFactor);
            if (_loc_3.enableMask && param1.layer != Layer3DManager.warpLayer)
            {
                Global3D.scene.context.setStencilReferenceValue(1);
            }
            return;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            super.dispose();
            this._particleParams = null;
            this._globlePoint.setTo(0, 0, 0);
            this._oldGloblePoint.setTo(0, 0, 0);
            this._oldControlPoint.setTo(0, 0, 0);
            this.timeOffset = null;
            this._distanceBirthNum = 0;
            this._maxDuring = 0;
            this._perMaxDuring = 0;
            this._playMode = 0;
            this.hasUpload = false;
            this._transformMatrix3d = null;
            this._faceCameraRegister = null;
            this.vc0_60 = new Vector.<Number>;
            this.globlePositionRegist = null;
            this.endPositionRegist = null;
            this._emitterTime = 0;
            this._curStarPlayTime = 0;
            this.preDuring = -1;
            this._oldIndex = 0;
            this._toltalParticleNum = 0;
            this._numOfMeshVertex = 1;
            this._perParticleEmitterTime = 0;
            this._emmitFinish = false;
            this._birthDistance = 0;
            this.curIndex = 0;
            this.tailMaxDistance = 0;
            this.tailPerDistance = 0;
            this._needUpdataTail = false;
            this._needUpDistanceBirth = false;
            this.useEndPoint = false;
            this._targetMultyplaySpeed = 0;
            this._targetStartPos = null;
            this._targetEndPos = null;
            this._preFrame = -1;
            this._preTime = 0;
            this._particleCircles = null;
            this.lineRoadControler = null;
            this.emmitFlag = 1;
            return;
        }// end function

        private function updateIndividualPos(param1:Number) : void
        {
            var _loc_4:int = 0;
            var _loc_5:Number = NaN;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            if (!this._particleCircles)
            {
                this._particleCircles = new Vector.<int>;
            }
            if (this._particleCircles.length < this._toltalParticleNum)
            {
                _loc_4 = this._particleCircles.length;
                while (_loc_4 < this._toltalParticleNum)
                {
                    
                    this._particleCircles[_loc_4] = -65535;
                    _loc_4++;
                }
            }
            if (!this.selfIndividualBuffer)
            {
                this.selfIndividualBuffer = new Vector.<Number>(this._toltalParticleNum * this._numOfMeshVertex * 4);
                _loc_4 = 0;
                while (_loc_4 < this._toltalParticleNum * this._numOfMeshVertex)
                {
                    
                    this.selfIndividualBuffer[_loc_4 * 4] = this._globlePoint.x;
                    this.selfIndividualBuffer[_loc_4 * 4 + 1] = this._globlePoint.y;
                    this.selfIndividualBuffer[_loc_4 * 4 + 2] = this._globlePoint.z;
                    this.selfIndividualBuffer[_loc_4 * 4 + 3] = 0;
                    _loc_4++;
                }
            }
            var _loc_2:Boolean = false;
            var _loc_3:int = 0;
            while (_loc_3 < this._toltalParticleNum)
            {
                
                _loc_5 = (param1 - _loc_3 * this._perParticleEmitterTime) / this._particleParams.emitterLife;
                if (_loc_5 > 0)
                {
                    _loc_5 = _loc_5 - 1e-008;
                }
                _loc_6 = Math.floor(_loc_5);
                if (_loc_6 != this._particleCircles[_loc_3])
                {
                    this._particleCircles[_loc_3] = _loc_6;
                    _loc_2 = true;
                    _loc_7 = _loc_3 * this._numOfMeshVertex;
                    _loc_8 = 0;
                    while (_loc_8 < this._numOfMeshVertex)
                    {
                        
                        this.selfIndividualBuffer[(_loc_7 + _loc_8) * 4] = this._globlePoint.x;
                        this.selfIndividualBuffer[(_loc_7 + _loc_8) * 4 + 1] = this._globlePoint.y;
                        this.selfIndividualBuffer[(_loc_7 + _loc_8) * 4 + 2] = this._globlePoint.z;
                        this.selfIndividualBuffer[(_loc_7 + _loc_8) * 4 + 3] = 0;
                        _loc_8++;
                    }
                }
                _loc_3++;
            }
            return;
        }// end function

    }
}
